home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlib43 / mntlib / fgets.c < prev    next >
C/C++ Source or Header  |  1992-09-17  |  423b  |  23 lines

  1. /* from Dale Schumacher's dLibs */
  2.  
  3. #include <stdio.h>
  4. #include <stddef.h>
  5. #include <assert.h>
  6.  
  7. char *fgets(data, limit, fp)
  8.     char *data;
  9.     register int limit;
  10.     register FILE *fp;
  11.     {
  12.     register char *p = data;
  13.     register int c = EOF;
  14.  
  15.     assert((data != NULL));
  16.  
  17.     while((--limit > 0) && ((c = getc(fp)) != EOF))
  18.         if((*p++ = c) == '\n')
  19.             break;
  20.     *p = '\0';
  21.     return((c == EOF && p == data) ? NULL : data);    /* NULL == EOF */
  22.     }
  23.